//
//  GreatGodViewModel.m
//  MoXiProject
//
//  Created by 周筱雯 on 2017/7/10.
//  Copyright © 2017年 周筱雯. All rights reserved.
//

#import "GreatGodViewModel.h"
#import "GreatGodModel.h"

@implementation GreatGodViewModel
- (instancetype)init
{
    self = [super init];
    if (self) {
        self.finduserArrayList = [[NSMutableArray alloc] initWithCapacity:0];
        self.searchArrayList = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return self;
}

-(RACSignal *)findUserBuyInfoRequestParameter:(NSString *) type
{
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        
        NSDictionary * parma = @{@"typeId":[NSString stringWithFormat:@"%@",type]};
        
       [ScyRequestOperationManager findUserBuyInfoParametersDic:parma success:^(NSDictionary *result) {
           
           if (result) {
               
               if ([self.finduserArrayList count] == 0) {
                   [self.finduserArrayList removeAllObjects];
               }
               
               NSLog(@"%@",result);
               
               [self.finduserArrayList addObjectsFromArray:(NSMutableArray *)[MTLJSONAdapter modelsOfClass:[GreatGodModel class] fromJSONArray:result[@"result"] error:nil]];

           }
           
           [subscriber sendNext:result];
           [subscriber sendCompleted];
           
       } failture:^(id result) {
           
           [self.finduserArrayList removeAllObjects];
           [subscriber sendError:result];
       }];
        
        return nil;
    }];
}

-(RACSignal *)searchUserNameRequestParameter:(NSString *)userName{
   
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        
        NSDictionary * parma = @{@"username":userName};
        
        [RequestOperationManager searchGreatGodSignNamePwdParametersDic:parma success:^(NSDictionary *result) {
            
            if (result) {
                
                if ([self.searchArrayList count] == 0) {
                    [self.searchArrayList removeAllObjects];
                }
                
                self.searchArrayList = (NSMutableArray *)[MTLJSONAdapter modelsOfClass:[SearchGodModel class] fromJSONArray:result[@"result"] error:nil];
                
            }
            
            [subscriber sendNext:result];
            [subscriber sendCompleted];
            
        } failture:^(id result) {
            
            [self.searchArrayList removeAllObjects];
            [subscriber sendError:result];
        }];
        
        return nil;
    }];
    
}
@end
